<template>
  <div>
    <div @keyup.enter="getData()">
      <el-form class="query-table-form" :inline="true">
        <el-form-item>
          <el-input v-model="params.customer_name" placeholder="项目名称查询" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="params.corp_name"
            placeholder="负责人查询"
            :clearable="true"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <select-address
            v-model="params.address_code"
            clearable
            placeholder="地址查询"
            :auto-top="true"
            @change="getData()"
          ></select-address>
        </el-form-item>
        <el-form-item>
          <c-select
            v-model="params.recommend_status"
            clearable
            @change="getData()"
            placeholder="推荐状态"
            :options="enumRecommendStatus"
          ></c-select>
        </el-form-item>
        <el-form-item>
          <el-button @click="getData()">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button @click="exportExcel('推荐任务列表')" :loading="exportLoading">导出</el-button>
        </el-form-item>
      </el-form>
    </div>
    <c-table
      border
      v-loading="loading"
      :stripe="false"
      :columns="tableColumns"
      :data="tableData"
      height="76vh"
    ></c-table>

    <div class="query-pagination">
      <div></div>
      <el-pagination
        layout="total, prev, pager, next, jumper"
        :current-page.sync="params.index"
        :page-size="params.size"
        :total="totalCount"
        @current-change="getData"
      ></el-pagination>
    </div>

    <recommend-file
      :visible.sync="recommendVisible"
      :viewModel="viewModel"
      :related-data="relatedData"
      @success="handleEditSuccess"
    ></recommend-file>
  </div>
</template>
<script>
import RecommendFile from '@/gov/views/business/RecommendFile'
import { enumProjectType, enumRecommendStatus } from '@/gov/plugins/enum'
import taskTableMixin from '@/credit/mixin/task/taskTable'
import SelectAddress from '@/components/select/SelectAddress'
export default {
  components: {
    RecommendFile,
    SelectAddress,
  },
  mixins: [taskTableMixin],
  props: {},
  data() {
    return {
      enumProjectType,
      loading: false,
      order: { recommend_time: 'desc' },
      params: {
        index: 1,
        size: 10,
        'submit_type.eq': 1,
      },
      enumRecommendStatus,
      tableData: [],
      tableColumns: [
        { attrs: { label: '未推荐主体', prop: 'customer_name', align: 'center' } },
        { attrs: { label: '地址', prop: 'address', align: 'center' } },
        { attrs: { label: '负责人', prop: 'corp_name', align: 'center' } },
        { attrs: { label: '联系电话', prop: 'mobile_no', align: 'center' } },
        { attrs: { label: '项目类型', prop: 'project_type_label', align: 'center' } },
        { attrs: { label: '项目状态', prop: 'statusLabel', align: 'center' } },
        {
          attrs: { label: '操作', align: 'center' },
          operations: [
            {
              name: '去推荐',
              event: this.handleEdit,
              ifRender: row => +row.recommend_status === 0,
            },
            {
              name: '推荐详情',
              event: this.handleEdit,
              ifRender: row => +row.recommend_status === 1,
            },
          ],
        },
      ],

      recommendVisible: false,
      relatedData: {},

      viewModel: false,
    }
  },
  computed: {},
  watch: {
    visible() {
      if (this.visible) {
        this.getData()
      }
    },
  },
  created() {
    this.params.address_code = this.$utils.getAddressCode()
    this.params['task_status.eq'] = this.status
    this.params['task_type.eq'] = this.type
  },
  mounted() {},
  methods: {
    getParams() {
      return this.params
    },
    getTabData() {
      this.getData()
    },
    handleEdit(row) {
      this.viewModel = +row.task_status === 1
      this.relatedData = { ...row }
      this.recommendVisible = true
    },
    dataAdapter(item) {
      item.statusLabel = enumRecommendStatus[item.recommend_status] || '-'
      item.project_type_label = enumProjectType[+item.project_type] || '-'
      return item
    },
    handleEditSuccess() {
      this.$store.dispatch('getMyTaskCount')
      this.$emit('success', true)
    },
  },
}
</script>
<style lang="scss" scoped></style>
